/**
 * 
 */
package com.pocketsweet.dao;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * @author bobhu 系统配置
 */
public class SystemConfigManager {
	private static final String SYSTEM_CONFIG = "system_config";
	private Context mContext;
	private SharedPreferences mSetting;
	private Editor mEditor;
	private static SystemConfigManager _instance;

	private SystemConfigManager(Context ctx) {
		mContext = ctx;
		mSetting = mContext.getSharedPreferences(SYSTEM_CONFIG, 0);
		mEditor = mSetting.edit();
	}

	public static SystemConfigManager getInstance(Context ctx) {
		if (_instance == null) {
			_instance = new SystemConfigManager(ctx);
		}
		return _instance;
	}

	private boolean getBooleanValue(String key, boolean defaultValue) {
		return mSetting.getBoolean(key, defaultValue);
	}

	private void setBooleanValue(String key, boolean value) {
		mEditor.putBoolean(key, value).commit();
	}

	@SuppressWarnings("unused")
	private void setStringValue(String key, String value) {
		mEditor.putString(key, value).commit();
	}

	@SuppressWarnings("unused")
	private String getStringValue(String key, String defaultValue) {
		return mSetting.getString(key, defaultValue);
	}

	private final String IS_FIRST_RUN = "is_first_run";
	private final String IS_FIRST_LOGIN= "is _first_login";

	public boolean isFirstRun() {
		return getBooleanValue(IS_FIRST_RUN, true);
	}

	public void setFirstRun(boolean bFirstRun) {
		setBooleanValue(IS_FIRST_RUN, bFirstRun);
	}
	
	public boolean isFirstLogin() {
		return getBooleanValue(IS_FIRST_LOGIN, true);
	}

	public void setFirstLogin(boolean bFirstlogin) {
		setBooleanValue(IS_FIRST_LOGIN, bFirstlogin);
	}
}
